package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.utils.CommonUtils;

import java.util.List;

/**
 * Created by wangqi on 2017/11/23.
 * 带有红色数量的tablayout
 */

public class TabNumberAdapter extends FragmentStatePagerAdapter {

    private List<Fragment> list;
    private String[] titles;

    public TabNumberAdapter(FragmentManager fm, List<Fragment> list, String[] titles) {
        super(fm);
        this.list = list;
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    public View getTabView(Context context, int position, int count){
        View view = LayoutInflater.from(context).inflate(R.layout.tab_number_item, null);
        TextView tvTitle=  view.findViewById(R.id.tv_title);
        tvTitle.setText(titles[position]);
        TextView tvBar=  view.findViewById(R.id.tv_bar);
        CommonUtils.setBarTextView(tvBar,count);
        return view;
    }

}
